package com.xing.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xing.dao.ProjectDao;
import com.xing.model.ProjectInfo;
import com.xing.util.Util;

@Service
public class ProjectService {

	@Resource
	private ProjectDao dao;
	
	public void setDao(ProjectDao dao) {
		this.dao = dao;
	}

	public void addProject(ProjectInfo info) {
		
		dao.addProject(info);
	}
	
	public Map<String, Object> getProjectInfo(int id) {
		
		List<String> conditionList = new ArrayList<String>();
		conditionList.add("c.projectId=" + id);
		
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getListAndCount(conditionList, null, null).get("rows");
		if (!Util.isEmpty(list)) {
			return list.get(0);
		} else {
			return null;
		}
	}
	
	public void updateProject(ProjectInfo info) {
		
		dao.updateProject(info);
	}
	
	public void deleteProject(String idStr) {
		
		String[] arr = idStr.split(",");
		List<Integer> idList = new ArrayList<Integer>();
		for (String tmp : arr) {
			idList.add(Integer.parseInt(tmp));
		}
		
		dao.deleteProject(idList);
	}
	
	public Map<String, Object> getListAndCount(List<String> conditionList, int page, int pageRow) {
		
		return dao.getListAndCount(conditionList, page, pageRow);
	}
	
}
